package com.zxl.designpattern.behavioral.observer;

/**
 * 天气预报显示
 * 实现了Observer和DisplayElement接口，根据当前天气数据预测未来天气
 */
public class ForecastDisplay implements Observer, DisplayElement {
    private double currentPressure = 1013.2;  // 当前气压
    private double lastPressure;              // 上次气压
    
    @Override
    public void update(double temperature, double humidity, double pressure) {
        lastPressure = currentPressure;
        currentPressure = pressure;
        display();
    }
    
    @Override
    public void display() {
        System.out.print("天气预报: ");
        if (currentPressure > lastPressure) {
            System.out.println("天气转晴，气温升高");
        } else if (currentPressure == lastPressure) {
            System.out.println("天气维持现状");
        } else {
            System.out.println("气温下降，可能有雨");
        }
    }
}    